package tt;

import java.util.*;


public class Main {
    public static void main(String[] args) {
    }
    static class pos{
        int x;
        int y;

        pos(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
    public static void Q1() {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        int m = Integer.parseInt(line.split(",")[0]);
        int n = Integer.parseInt(line.split(",")[1]);
        int[][] player = new int[m][n];
        for (int i = 0; i < m; i++) {
            line = scanner.nextLine();
            for (int j = 0; j < n; j++) {
                player[i][j] = Integer.parseInt(line.split(",")[j]);
            }
        }
        boolean[][] paresd = new boolean[m][n];
        int count = 0;
        int max = 0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (!paresd[i][j]) {
                    if (player[i][j] == 0) {
                        paresd[i][j] = true;
                        continue;
                    } else {
                        count++;
                        Queue<pos> queue = new LinkedList<pos>();
                        queue.offer(new pos(i, j));
                        int r = helper(paresd, queue, player, m, n);
                        if (r > max) {
                            max = r;
                        }
                    }
                }
            }
        }
        System.out.println(count + "," + max);
    }
    public static int helper(boolean[][] flag, Queue<pos> queue, int[][] player, int m, int n) {
        int count = 0;
        while (!queue.isEmpty()) {
            pos pos = queue.poll();
            if (!flag[pos.x][pos.y]) {
                if (pos.x - 1 >= 0 && player[pos.x - 1][pos.y] == 1) {
                    queue.offer(new pos(pos.x - 1, pos.y));
                } if (pos.x + 1 < m && player[pos.x + 1][pos.y] == 1) {
                    queue.offer(new pos(pos.x + 1, pos.y));
                } if (pos.y - 1 >= 0 && player[pos.x][pos.y - 1] == 1) {
                    queue.offer(new pos(pos.x, pos.y - 1));
                } if (pos.y + 1 < n && player[pos.x][pos.y + 1] == 1) {
                    queue.offer(new pos(pos.x, pos.y + 1));
                } if (pos.y + 1 < n && pos.x - 1 >= 0 && player[pos.x - 1][pos.y + 1] == 1) {
                    queue.offer(new pos(pos.x - 1, pos.y + 1));
                } if (pos.y - 1 >= 0 && pos.x - 1 >= 0 && player[pos.x - 1][pos.y - 1] == 1) {
                    queue.offer(new pos(pos.x - 1, pos.y - 1));
                } if (pos.y + 1 < n && pos.x + 1 < m && player[pos.x + 1][pos.y + 1] == 1) {
                    queue.offer(new pos(pos.x + 1, pos.y + 1));
                } if (pos.y - 1 >= 0 && pos.x + 1 < m && player[pos.x + 1][pos.y - 1] == 1) {
                    queue.offer(new pos(pos.x + 1, pos.y - 1));
                }
                count++;
                flag[pos.x][pos.y] = true;
            }
        }
        return count;
    }







}
